package com.tts.hbdao;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;

import com.tts.hbentity.LineScenery;

/**
 * Data access object (DAO) for domain model class LineScenery.
 * 
 * @see com.tts.hbentity.LineScenery
 * @author MyEclipse Persistence Tools
 */

public class LineSceneryDAO extends BaseHibernateDAO {
	private static final Log log = LogFactory.getLog(LineSceneryDAO.class);
	// property constants
	public static final String SORT_ID = "sortId";
	public static final String LINE_SCENERY_INTRODUCE = "lineSceneryIntroduce";

	public void save(LineScenery transientInstance) {
		log.debug("saving LineScenery instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(LineScenery persistentInstance) {
		log.debug("deleting LineScenery instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public LineScenery findById(java.lang.Integer id) {
		log.debug("getting LineScenery instance with id: " + id);
		try {
			LineScenery instance = (LineScenery) getSession().get(
					"com.tts.hbdao.LineScenery", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(LineScenery instance) {
		log.debug("finding LineScenery instance by example");
		try {
			List results = getSession().createCriteria(
					"com.tts.hbdao.LineScenery").add(Example.create(instance))
					.list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding LineScenery instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from LineScenery as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findBySortId(Object sortId) {
		return findByProperty(SORT_ID, sortId);
	}

	public List findByLineSceneryIntroduce(Object lineSceneryIntroduce) {
		return findByProperty(LINE_SCENERY_INTRODUCE, lineSceneryIntroduce);
	}

	public List findAll() {
		log.debug("finding all LineScenery instances");
		try {
			String queryString = "from LineScenery";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public LineScenery merge(LineScenery detachedInstance) {
		log.debug("merging LineScenery instance");
		try {
			LineScenery result = (LineScenery) getSession().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(LineScenery instance) {
		log.debug("attaching dirty LineScenery instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(LineScenery instance) {
		log.debug("attaching clean LineScenery instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}